package com.compass.doctor.ui.home

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.compass.doctor.databinding.ActivityMedicalCareBinding
import com.compass.doctor.ui.home.fragment.CareExecutedFragment
import com.compass.doctor.ui.home.fragment.CareImplementedFragment
import com.compass.framework.adapter.ViewPage2FragmentAdapter
import com.compass.doctor.base.BaseVBActivity
import com.compass.doctor.ui.home.fragment.AfterSaleFragment
import com.compass.framework.constant.KEY_INDEX
import com.compass.framework.constant.KEY_ORDER_TYPE

/**
 * Description： 医护上门/医护到家
 * Date:2023/12/11 20:58
 */
class MedicalCareActivity : BaseVBActivity<ActivityMedicalCareBinding>() {

    private lateinit var viewPageAdapter: ViewPage2FragmentAdapter
    private var fragments: ArrayList<Fragment> = ArrayList()
    private lateinit var careImplementedFragment: CareImplementedFragment
    private lateinit var careExecutedFragment: CareExecutedFragment
    private lateinit var afterSaleFragment: AfterSaleFragment

    companion object {
        fun start(context: Context, index: Int = 0) {
            val intent = Intent(context, MedicalCareActivity::class.java)
            intent.putExtra(KEY_INDEX, index)
            context.startActivity(intent)
        }
    }


    override fun initView(savedInstanceState: Bundle?) {

        initFragment()
        mBinding.dslTab.tabIndicator.indicatorWidth = -2
        mBinding.dslTab.tabIndicator.indicatorEnableFlow = true
        mBinding.dslTab.configTabLayoutConfig {
            onSelectIndexChange = { _, selectIndexList, _, _ ->
                val toIndex = selectIndexList.first()
                mBinding.viewpager2.setCurrentItem(toIndex, false)

            }
        }
        viewPageAdapter = ViewPage2FragmentAdapter(supportFragmentManager, lifecycle, fragments)
        mBinding.viewpager2.adapter = viewPageAdapter
        mBinding.viewpager2.isUserInputEnabled = false//禁止viewPage滑动
        mBinding.viewpager2.setCurrentItem(0, false)
    }

    private fun initFragment() {

        careImplementedFragment = CareImplementedFragment()
        fragments.add(careImplementedFragment)

        careExecutedFragment = CareExecutedFragment()
        fragments.add(careExecutedFragment)

//        afterSaleFragment = AfterSaleFragment()
//        fragments.add(afterSaleFragment)

    }
}